using System;
using System.Collections.Generic;
using System.Text;
using HCP.Responses;
using HCP.SimpleJSON;
using JsonFx.Json;
using UnityEngine;

namespace HCP.Requests
{
	public class GetUnityCommandList : JobRequest
	{
		public GetUnityCommandList(JSONClass json) : base(json)
		{
			this.serverObject = GameObject.Find("AppiumServer").GetComponent<Server>();
		}

		public override JobResponse Process()
		{
			string value = string.Empty;
			if (this.serverObject != null)
			{
				value = this.GetCommandListToString();
			}
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			dictionary["commands"] = value;
			JsonWriterSettings jsonWriterSettings = new JsonWriterSettings();
			jsonWriterSettings.PrettyPrint = false;
			if (this.builder != null)
			{
				this.builder.Length = 0;
			}
			else
			{
				this.builder = new StringBuilder();
			}
			using (JsonWriter jsonWriter = new JsonWriter(this.builder, jsonWriterSettings))
			{
				jsonWriter.Write(dictionary);
			}
			return new StringResponse(this.builder.ToString());
		}

		private string GetCommandListToString()
		{
			List<string> requestCommands = this.serverObject.requestCommands;
			if (this.builder == null)
			{
				this.builder = new StringBuilder();
			}
			else
			{
				this.builder.Length = 0;
			}
			foreach (string value in requestCommands)
			{
				this.builder.Append(value);
				this.builder.Append(", ");
			}
			return this.builder.ToString();
		}

		private Server serverObject;

		private StringBuilder builder;
	}
}
